package com.meedoll.manager.std.client.mainpanel;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.meedoll.manager.std.client.mainpanel.composites.JinHuoManagerComposite;
import com.meedoll.manager.std.client.mainpanel.composites.XiaoShouManagerComposite;

public class FuZhuangMainUi extends PopupPanel {
//private static final	FlexTable flexTable_content = new FlexTable();
	public FuZhuangMainUi() {
		super(true);
		final FlexTable flexTable_content = new FlexTable();

		flexTable_content.setSize("629px", "347px");
		flexTable_content.setBorderWidth(2);
		
		VerticalPanel verticalPanel = new VerticalPanel();
		setWidget(verticalPanel);
		verticalPanel.setSize("100%", "193px");
		
		MenuBar menuBar = new MenuBar(false);
		verticalPanel.add(menuBar);
		verticalPanel.setCellWidth(menuBar, "100%");
		
		MenuItem menuItem = new MenuItem("New item", false, (Command) null);
		menuBar.addItem(menuItem);
		
		MenuItem menuItem_1 = new MenuItem("New item", false, (Command) null);
		menuBar.addItem(menuItem_1);
		
		MenuItem menuItem_2 = new MenuItem("New item", false, (Command) null);
		menuBar.addItem(menuItem_2);
		
		MenuItem menuItem_3 = new MenuItem("New item", false, (Command) null);
		menuBar.addItem(menuItem_3);
		
		MenuItem menuItem_4 = new MenuItem("New item", false, (Command) null);
		menuBar.addItem(menuItem_4);
		
		final FlexTable flexTable_layout = new FlexTable();
		flexTable_layout.setBorderWidth(1);
		verticalPanel.add(flexTable_layout);
		verticalPanel.setCellHeight(flexTable_layout, "600px");
		verticalPanel.setCellWidth(flexTable_layout, "100%");
		flexTable_layout.setSize("100%", "600px");
		
		com.smartgwt.client.widgets.Button xiaoshou_btn = new com.smartgwt.client.widgets.Button("销售管理");
		xiaoshou_btn.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
			public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
				//flexTable_content.clear();
				GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler(){

					@Override
//					public void onUncaughtException(Throwable e) {
//						// TODO Auto-generated method stub
//						System.out.println(e.getMessage()+"=====================");
//					}
					  public void onUncaughtException(Throwable throwable) {
				        String text = "Uncaught exception: ";
				        while (throwable != null) {
				            StackTraceElement[] stackTraceElements = throwable
				                    .getStackTrace();
				            text += throwable.toString() + "\n";
				            for (int i = 0; i < stackTraceElements.length; i++) {
				                text += "    at " + stackTraceElements[i] + "\n";
				            }
				            throwable = throwable.getCause();
				            if (throwable != null) {
				                text += "Caused by: ";
				            }
				        }
				        System.err.print(text);
				        text = text.replaceAll(" ", " ");
				        System.out.println("系统错误："+text);
				        //Window.alert("系统错误："+text);
				    }
					
				}
				);
				flexTable_layout.setWidget(0, 1, new XiaoShouManagerComposite(flexTable_content));
				
			}
		});
		flexTable_layout.setWidget(0, 0, xiaoshou_btn);
		flexTable_layout.getCellFormatter().setHeight(0, 0, "20%");
		//默认设置
		flexTable_layout.setWidget(0, 1, new JinHuoManagerComposite(flexTable_content));
		
		com.smartgwt.client.widgets.Button jinhuo_btn = new com.smartgwt.client.widgets.Button("进货管理");
		jinhuo_btn.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
			public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
				flexTable_content.clear();
				//flexTable_layout.clear();
				flexTable_layout.setWidget(0, 1, new JinHuoManagerComposite(flexTable_content));
			}
		});
		flexTable_layout.setWidget(1, 0, jinhuo_btn);
		flexTable_layout.getCellFormatter().setWidth(1, 0, "15%");
		flexTable_layout.getCellFormatter().setHeight(1, 0, "20%");
		
		com.smartgwt.client.widgets.Button kucun_button = new com.smartgwt.client.widgets.Button("库存管理");
		kucun_button.setHeight(22);
		flexTable_layout.setWidget(2, 0, kucun_button);
		flexTable_layout.getCellFormatter().setHeight(2, 0, "20%");
		
		com.smartgwt.client.widgets.Button monery_btn = new com.smartgwt.client.widgets.Button("钱流管理");
		flexTable_layout.setWidget(3, 0, monery_btn);
		flexTable_layout.getCellFormatter().setHeight(3, 0, "20%");
		com.smartgwt.client.widgets.Button sys_btn = new com.smartgwt.client.widgets.Button("系统维护");
		sys_btn.setHeight(22);
		flexTable_layout.setWidget(4, 0, sys_btn);
		flexTable_layout.getCellFormatter().setWidth(4, 0, "100");
		flexTable_layout.getCellFormatter().setHeight(4, 0, "20%");
		flexTable_layout.getFlexCellFormatter().setRowSpan(0, 1, 5);
		flexTable_layout.getCellFormatter().setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_CENTER);
		flexTable_layout.getCellFormatter().setVerticalAlignment(3, 0, HasVerticalAlignment.ALIGN_MIDDLE);
		flexTable_layout.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
		flexTable_layout.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
		flexTable_layout.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
		flexTable_layout.getCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
		flexTable_layout.getCellFormatter().setVerticalAlignment(2, 0, HasVerticalAlignment.ALIGN_MIDDLE);
		flexTable_layout.getCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_CENTER);
		flexTable_layout.getCellFormatter().setHorizontalAlignment(4, 0, HasHorizontalAlignment.ALIGN_CENTER);
		flexTable_layout.getCellFormatter().setVerticalAlignment(4, 0, HasVerticalAlignment.ALIGN_MIDDLE);
		FlexTableHelper.fixRowSpan(flexTable_layout);
	}

	
}
